import pythoncom
import wmi
import threading
import Queue

class Server (threading.Thread):
  def __init__ (self, results):
    threading.Thread.__init__(self)
    self.results = results
    self.setDaemon(True)

  def run (self):
    pythoncom.CoInitialize ()
    try:
      c = wmi.WMI()
      watcher = c.Win32_DeviceChangeEvent.watch_for()
      while True:
        self.results.put(watcher())
    finally:
      pythoncom.CoUninitialize()


if __name__ == '__main__':
  events = Queue.Queue()
  print "Watching..."
  Server(events).start()

  while True:
    event = events.get()
    print "=>", event.EventType